class RecipeController < ApplicationController
	layout "standard-layout"
	scaffold :recipe
	
	def new
		@recipe = Recipe.new
		@categories = Category.find_all
		@ingredients = Ingredient.find_all
	end
	
	def create 
		@recipe = Recipe.new(@params['recipe']) 
		@recipe.date = Date.today 
		if @recipe.save 
		  redirect_to :action => 'list' 
		else 
		  render_action 'new' 
		end
	end

	def delete
		Recipe.find(@params['id']).destroy
		redirect_to :action => 'list'
	end
	
	def list
		@recipes = Recipe.find_all
		@category = @params['category']
		@ingredient = @params['ingredient']
	end
	
	def listByCategory
		@category = @params['category']
		@recipes = Recipe.find_all
	end
	
	def listByIngredient
		@ingredient = @params['ingredient']
		@recipes = Recipe.find_all
	
	end
	
	def edit
	  @recipe = Recipe.find(@params["id"])
	  @categories = Category.find_all
	  @ingredients = Ingredient.find_all
	end
end
